package org.xqh.test.regex;

import com.alibaba.fastjson.JSONPath;
import com.google.common.collect.Lists;
import org.xqh.utils.excel.ExcelReader;
import org.xqh.utils.file.ReadTxtFileUtils;

import java.io.File;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @ClassName RegexTest3
 * @Description TODO
 * @Author xuqianghui
 * @Date 2025/4/9 16:05
 * @Version 1.0
 */
public class RegexTest3 {

    public static String sql = "INSERT INTO isp_config(id, as_name, isp, create_time) VALUES(%s, '%s', '%s', '2025-04-16 18:03:00');";


    public static void main(String[] args) {
        String text = "<li class=\"clearfix\"><span class=\"l\">71.163.239.0</span><span class=\"r\">71.163.239.255</span></li><li class=\"clearfix\"><span class=\"l\">71.163.252.0</span>";
        String regex = "<span class=\"l\">(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})</span>";
        Pattern connectPattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
        Matcher matcher = connectPattern.matcher(text);
        if(matcher.matches()){
            System.out.println(matcher.group());
        }
    }
    public static void main111(String[] args) {
        List<String[]> list = ExcelReader.getExcelData(new File("D:\\test\\国内运营商 ASN.xlsx"), 0, 2);
        List<String> sqlList = Lists.newArrayList();
        for(String[] item:list){
            if(item.length >=3 ){
//                System.out.println(item[0] + ", " + item[1] + ", " +item[2]);
                String sqlItem = String.format(sql, item[0].replace(".0", ""), item[1], item[2]);
                sqlList.add(sqlItem);
            }
        }

        ReadTxtFileUtils.writeToTxt(sqlList, "D:\\test\\isp_insert_3.txt");
    }

    public static void main123(String[] args) {
        String regex = "^as([0-9]+)(.*)";
        Pattern connectPattern = Pattern.compile("^as([0-9]+)\\|\\|(.*)", Pattern.CASE_INSENSITIVE);
        String txt = "AS9808||China Mobile Communications Group Co., Ltd.";
        Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
        Matcher matcher = connectPattern.matcher(txt);
        if(matcher.matches()){
            System.out.println(matcher.group(1));
            System.out.println(matcher.group(2));
        }
//        String json = "{\n" +
//                "    \"as\": \"AS9808 China Mobile Communications Group Co., Ltd.\",\n" +
//                "    \"city\": \"Guangzhou\",\n" +
//                "    \"country\": \"China\",\n" +
//                "    \"countryCode\": \"CN\",\n" +
//                "    \"isp\": \"China Mobile communications corporation\",\n" +
//                "    \"lat\": 23.1317,\n" +
//                "    \"lon\": 113.266,\n" +
//                "    \"org\": \"China Mobile\",\n" +
//                "    \"query\": \"221.180.121.162\",\n" +
//                "    \"region\": \"GD\",\n" +
//                "    \"regionName\": \"Guangdong\",\n" +
//                "    \"status\": \"success\",\n" +
//                "    \"timezone\": \"Asia/Shanghai\",\n" +
//                "    \"zip\": \"510000\"\n" +
//                "}";
//        System.out.println(JSONPath.read(json, "$.as"));
//        System.out.println(JSONPath.read(json, "$.as2"));
    }
}
